package cn.wen.yinxiu.member.controller;

import java.util.List;

import cn.wen.yinxiu.common.convention.result.Results;
import cn.wen.yinxiu.member.service.UsersService;
import cn.wen.yinxiu.member.vo.TalkBoxInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wen.yinxiu.member.service.TalkBoxService;
import cn.wen.yinxiu.common.convention.result.ResultEntity;


import static cn.wen.yinxiu.common.constant.Constant.TalkType.Friend;

/**
 * @ClassName: TalkBox
 * @Author 小飞
 * @Email coderwen22@163.com
 * @Date 2023-05-21 22:19:26
 * @Description:
 */
@RestController
@RequestMapping("/web")
public class TalkBoxController {

    @Autowired
    private TalkBoxService talkBoxService;

    /**
     * 聊天窗口列表
     *
     * @param userId
     * @return
     */
    @GetMapping("/api/user/box/list")
    public ResultEntity getTalkBoxList(@RequestParam("userId") Long userId,
                                       @RequestParam("talkPage") Integer talkPage) {
        List<TalkBoxInfo> talkBoxInfoList = talkBoxService.queryTalkBoxInfoList(userId, talkPage);
        return Results.success(talkBoxInfoList);
    }

    /**
     * 通过聊天类型获取聊天窗口列表
     *
     * @param userId
     * @return
     */
    @GetMapping("/api/user/box/type/list")
    public ResultEntity getFriendTalkBoxList(@RequestParam("userId") Long userId,
                                             @RequestParam("talkType") Integer talkType,
                                             @RequestParam("talkPage") Integer talkPage) {
        List<TalkBoxInfo> talkBoxInfoList = talkBoxService.queryTalkBoxInfoListByType(userId, talkType, talkPage);
        return Results.success(talkBoxInfoList);
    }


    /**
     * 添加聊天窗口（私聊窗口）
     *
     * @param userId
     * @return
     */
    @PostMapping("/api/user/chat/box/add")
    public ResultEntity deleteChatBox(@RequestParam("userId") Long userId,
                                      @RequestParam("talkId") Long talkId) {
        boolean res = talkBoxService.addTalkBoxInfo(userId, talkId, Friend.getCode());
        if (!res) return Results.failure();
        return Results.success();
    }

    /**
     * 设置置顶聊天
     *
     * @return
     */
    @PostMapping("/api/user/chat/box/top")
    public ResultEntity topChatTalkBox(@RequestParam("chatBoxId") Long chatBoxId) {
        boolean res = talkBoxService.topChatTalkBox(chatBoxId);
        if (!res) return Results.failure();
        return Results.success();
    }

    /**
     * 删除聊天窗口
     *
     * @return
     */
    @PostMapping("/api/user/chat/box/delete")
    public ResultEntity deleteChatTalkBox(@RequestParam("chatBoxId") Long chatBoxId) {
        boolean res = talkBoxService.deleteChatTalkBox(chatBoxId);
        if (!res) return Results.failure();
        return Results.success();
    }
}
